package com.yy.jhl.ui.manager.activity;

import android.content.Intent;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.yy.common.base.BaseActivity;
import com.yy.common.commonutils.KeyBordUtil;
import com.yy.common.commonwidget.OnNoDoubleClickListener;
import com.yy.jhl.R;
import com.yy.jhl.bean.FunctionInfo;
import com.yy.jhl.bean.ProjectInfo;
import com.yy.jhl.bean.UpdateInfo;
import com.yy.jhl.interfaces.MessageNumCallBack;
import com.yy.jhl.ui.manager.adapter.FunctionAdapter;
import com.yy.jhl.ui.manager.adapter.ProjectAdapter;
import com.yy.jhl.ui.manager.contract.FunctionContract;
import com.yy.jhl.ui.manager.contract.MenuOneContract;
import com.yy.jhl.ui.manager.presenter.FunctionPresenter;
import com.yy.jhl.ui.manager.presenter.MenuOnePresenter;
import com.yy.jhl.ui.qrcode.QRScanActivity;
import com.yy.jhl.util.DataRequestUtil;

import butterknife.BindView;

/**
 * Created by libingn on 2018/2/9.
 */

    public class FunctionIntroduceActivity extends BaseActivity<FunctionPresenter> implements FunctionContract.View,PullToRefreshBase.OnRefreshListener2 {
        @BindView(R.id.message_pull_list_view)
        PullToRefreshListView messagePullListView;
        ListView messageListView;
        FunctionAdapter functionAdapter;
        @BindView(R.id.no_data_parent)
        LinearLayout noDataParent;
        private int currentPage = 1;
        @Override
        public int getLayoutId() {
            return R.layout.act_function_introduce;
        }

        @Override
        public void initView() {
            messagePullListView.setMode(PullToRefreshBase.Mode.DISABLED);
            messageListView = messagePullListView.getRefreshableView();
            messageListView.setDividerHeight(2);
            functionAdapter = new FunctionAdapter(mContext);
            messageListView.setAdapter(functionAdapter);
            messagePullListView.setOnRefreshListener(this);
            showTitle("功能介绍", new OnNoDoubleClickListener() {
                @Override
                protected void onNoDoubleClick(View v) {
                    finish();
                }
            });
            mPresenter.getList(getResources().getString(R.string.version_name));
        }




        @Override
        public void onPullDownToRefresh(PullToRefreshBase refreshView) {
            functionAdapter.clearData();
            currentPage = 1;
//            mPresenter.getProjectList(currentPage, searchProjectName);
        }

        @Override
        public void onPullUpToRefresh(PullToRefreshBase refreshView) {
            currentPage += 1;
//            mPresenter.getProjectList(currentPage, searchProjectName);
        }

        @Override
        public void getSuccess(FunctionInfo projectInfo) {
            if (currentPage == 1){
                functionAdapter.clearData();
                if (projectInfo.getData() == null ||projectInfo.getData().size()== 0){
                    noDataParent.setVisibility(View.VISIBLE);
                    messagePullListView.setVisibility(View.GONE);
                }else {
                    noDataParent.setVisibility(View.GONE);
                    messagePullListView.setVisibility(View.VISIBLE);
                }
            }
            messagePullListView.onRefreshComplete();
            functionAdapter.addData(projectInfo.getData());

        }

    @Override
    public void getUpdateApkSuccess(boolean isShow,UpdateInfo projectInfo) {

    }

    @Override
        public void getFail() {
            messagePullListView.onRefreshComplete();
            noDataParent.setVisibility(View.VISIBLE);
            messagePullListView.setVisibility(View.GONE);
        }
    }
